#!/bin/bash
# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu
set -e

set +e
git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACDMRT \
| rg -v "experimental" \
| rg "(WORKSPACE|BUILD|^external/apiset$)|((\.bzl|\.c|\.cc|\.cpp|\.h|\.hpp)$)"

status=$?
set -e

if [ $status -eq 0 ]
then

source ~/miniconda3/etc/profile.d/conda.sh
conda activate coin2_env

echo '# ---------------------------------------------------------------------------- #'
echo '#                               Build Clang 10                                 #'
echo '# ---------------------------------------------------------------------------- #'
./build-clang.sh

echo '# ---------------------------------------------------------------------------- #'
echo '#                                coin_test_data                                #'
echo '# ---------------------------------------------------------------------------- #'
ssh-keygen -F gitea.prestolabs.io || ssh-keyscan gitea.prestolabs.io >> ~/.ssh/known_hosts
git lfs install --skip-repo
git clone git@gitea.prestolabs.io:prestolabs/coin_test_data.git ../coin_test_data

echo '# ---------------------------------------------------------------------------- #'
echo '#                                    doctest                                   #'
echo '# ---------------------------------------------------------------------------- #'
./bazel-bin/cc/coin2/test

echo '# ---------------------------------------------------------------------------- #'
echo '#                                     gtest                                    #'
echo '# ---------------------------------------------------------------------------- #'
./bazel-bin/cc/testcoin2/testcoin2

else
echo 'no WORKSPACE|BUILD|external/apiset|.bzl|.c|.cc|.cpp|.h|.hpp file changed.'
fi
